import pandas as pd
from pyecharts.charts import Map, MapGlobe,Map3D
from pyecharts import options as opts
from pyecharts.globals import ThemeType

#初始匹配字典
pieces = [
    {"min": 10000000},
    {"min": 1000000, "max": 9999999},
    {"min": 100000, "max": 999999},
    {"min": 10000, "max": 99999},
    {"min": 1000, "max": 9999},
    {"min": 0, "max": 999},
]

piecesC = [
    {"min": 10000,'color':'#7f1100'},
    {"min": 1000, "max": 9999,'color':'#bd1316'},
    {"min": 500, "max": 999,'color':'#e64b45'},
    {"min": 100, "max": 499,'color':'#ff8c71'},
    {"min": 1, "max": 99,'color':'#fdd2a0'},
    { "max": 1}
]
# init_opts=opts.InitOpts(theme=ThemeType.CHALK,width='1536px', height='672px')
# def draw_map(map_name,data1,data2,filename,type,pieces):
#     map_name = (
#             Map()
#             .add('total_confirm', data1,type,label_opts=opts.LabelOpts(color='#666',font_family='幼圆'),is_map_symbol_show=False)
#             .add('today_confirm', data2, type,label_opts=opts.LabelOpts(color='#666',font_family='幼圆'),is_map_symbol_show=False)
#             .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
#             .set_global_opts(
#             title_opts=opts.TitleOpts(title='Epidemic information of '+filename, pos_left='center',
#                                       subtitle_textstyle_opts=opts.TextStyleOpts(color='cyan',
#                                                                                  font_family='KaiTi',
#                                                                                  font_size=16)),
#             visualmap_opts=opts.VisualMapOpts(max_=10000, is_inverse=True, pieces=piecesC, is_piecewise=True,range_text=['H','L'],pos_top='center'),
#             legend_opts=opts.LegendOpts(pos_top='9%', textstyle_opts=opts.TextStyleOpts(color='black'), is_show=True,
#                                         selected_mode='single')
#
#         )
#     )
#     map_name.render(filename+'.html')



# 世界地图
df = pd.read_csv('xiugai_2022_07_27.csv',encoding='utf-8')
dfW = df[df['date'] == '2022-03-08']
name = pd.read_csv('translate.csv',encoding='utf-8')
name_C ={i:j for i,j in zip([a for a in name['English']],[b for b in name['chinese']])}

world_map = (
        MapGlobe(init_opts=opts.InitOpts(theme=ThemeType.CHALK,width='1400px', height='700px',bg_color='#00BFFF'))
        .add('today_confirm',dfW[['country_name','total_confirm']].values.tolist(), "world",name_map=name_C,is_map_symbol_show=False)
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
        title_opts=opts.TitleOpts(title='World epidemic information', pos_left='center',
                                      subtitle_textstyle_opts=opts.TextStyleOpts(color='cyan',
                                                                                 font_family='KaiTi',
                                                                                 font_size=16)),
        visualmap_opts=opts.VisualMapOpts(max_=1000000, is_piecewise=True, pieces=pieces),
        legend_opts=opts.LegendOpts(pos_top='6%',textstyle_opts=opts.TextStyleOpts(color='black'),is_show=True,selected_mode='single')
    )
)


world_map.render('world_map_GLO.html')
#

# 中国地图
# df = pd.read_csv('china_all_provinces_data_now_2022_07_19.csv',encoding='utf-8')
# draw_map('china3D',df[['name', 'total_confirm']].values.tolist(),df[['name', 'total_confirm']].values.tolist(),'china','china',pieces=piecesC)
#

#
# #省地图
# #选取适合数据
# dfP = pd.read_csv('city-province-data_2022_07_20.csv')
# province_list =set([ i for i in dfP['provinces']])
# print(province_list)
# add_list = ['市','土家族苗族自治州','自治区','地区','区','林区','恩施公土家族苗族自治区','州','县'
#         ,'朝鲜族自治州','新区','盟','县','傣族景颇族自治州','傈僳族自治州','藏族自治州','白族自治州','彝族自治州','哈尼族彝族自治州','壮族苗族自治州'
#         ,'傣族自治州','藏族羌族自治州','哈萨克自治州','蒙古自治州','柯尔克孜自治州','回族自治州','苗族自治县','黎族自治县','布依族苗族自治州','苗族侗族自治州'
#         ,'土家族苗族自治县','苗族土家族自治县','藏族自治州','蒙古族藏族自治州','','黎族苗族自治县','土家族自治县','兵团第八师','六师']
#
#
#
# for province in province_list:
#     data_pair1 = dfP[dfP['provinces']==province][['name', 'total_confirm']].values.tolist()
#     data_pair2 = dfP[dfP['provinces']==province][['name', 'today_confirm']].values.tolist()
#     data_pairs1 =[[f"{i[0] + j}",i[1]] for i in data_pair1 for j in add_list ]
#     data_pairs2 = [[f"{i[0] + j}",i[1]] for i in data_pair2 for j in add_list]
#     draw_map(province,data_pairs1,data_pairs2,province,province,pieces=piecesC)
